home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / GDEVMEM1.C < prev    next >
C/C++ Source or Header  |  1993-05-26  |  18KB  |  560 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdevmem1.c */
  20. /* Generic and monobit "memory" (stored bitmap) device */
  21. /* for Ghostscript library. */
  22. #include "memory_.h"
  23. #include "gx.h"
  24. #include "gserrors.h"
  25. #include "gxdevice.h"
  26. #include "gxdevmem.h"            /* semi-public definitions */
  27. #include "gdevmem.h"            /* private definitions */
  28.  
  29. /* Define masks for little-endian operation. */
  30. const ushort gdev_mem_swapped_left_masks[17] = {
  31.     0xffff, 0xff7f, 0xff3f, 0xff1f, 0xff0f, 0xff07, 0xff03, 0xff01,
  32.     0xff00, 0x7f00, 0x3f00, 0x1f00, 0x0f00, 0x0700, 0x0300, 0x0100,
  33.     0x0000
  34. };
  35.  
  36. /* ------ Generic code ------ */
  37.  
  38. /* Return the appropriate memory device for a given */
  39. /* number of bits per pixel (0 if none suitable). */
  40. const gx_device_memory *
  41. gdev_mem_device_for_bits(int bits_per_pixel)
  42. {    switch ( bits_per_pixel )
  43.        {
  44.     case 1: return &mem_mono_device;
  45.     case 2: return &mem_mapped2_color_device;
  46.     case 4: return &mem_mapped4_color_device;
  47.     case 8: return &mem_mapped8_color_device;
  48.     case 16: return &mem_true16_color_device;
  49.     case 24: return &mem_true24_color_device;
  50.     case 32: return &mem_true32_color_device;
  51.     default: return 0;
  52.        }
  53. }
  54.  
  55. /* Compute the size of the bitmap storage, */
  56. /* including the space for the scan line pointer table. */
  57. /* Note that scan lines are padded to a multiple of 4 bytes, */
  58. /* and additional padding may be needed if the pointer table */
  59. /* must be aligned 0 mod 8. */
  60. private ulong
  61. mem_bitmap_bits_size(const gx_device_memory *dev)
  62. {    return round_up((ulong)dev->height * gdev_mem_raster(dev),
  63.             max(4, arch_align_long_mod));
  64. }
  65. ulong
  66. gdev_mem_bitmap_size(const gx_device_memory *dev)
  67. {        return mem_bitmap_bits_size(dev) +
  68.         (ulong)dev->height * sizeof(byte *);
  69. }
  70.  
  71. /* Open a memory device, allocating the data area if appropriate, */
  72. /* and create the scan line table. */
  73. int
  74. mem_open(gx_device *dev)
  75. {    byte *scan_line;
  76.     uint raster = mdev->raster = gdev_mem_raster(mdev);
  77.     byte **pptr;
  78.     byte **pend;
  79.     if ( mdev->memory_procs != 0 )
  80.     {    /* Allocate the data now. */
  81.         ulong size = gdev_mem_bitmap_size(mdev);
  82.         if ( (uint)size != size )
  83.             return gs_error_limitcheck;
  84.         mdev->base = (byte *)(*mdev->memory_procs->alloc)(1, (uint)size, "mem_open");
  85.         if ( mdev->base == 0 )
  86.             return gs_error_VMerror;
  87.     }
  88.     scan_line = mdev->base;
  89.         pptr = (byte **)byte_ptr_add(scan_line, mem_bitmap_bits_size(mdev));
  90.     pend = pptr + dev->height;
  91.     mdev->line_ptrs = pptr;
  92.     while ( pptr < pend )
  93.        {    *pptr++ = scan_line;
  94.         scan_line = byte_ptr_add(scan_line, raster);
  95.        }
  96.     return 0;
  97. }
  98.  
  99. /* Return the initial transformation matrix */
  100. void
  101. mem_get_initial_matrix(gx_device *dev, gs_matrix *pmat)
  102. {    pmat->xx = mdev->initial_matrix.xx;
  103.     pmat->xy = mdev->initial_matrix.xy;
  104.     pmat->yx = mdev->initial_matrix.yx;
  105.     pmat->yy = mdev->initial_matrix.yy;
  106.     pmat->tx = mdev->initial_matrix.tx;
  107.     pmat->ty = mdev->initial_matrix.ty;
  108. }
  109.  
  110. /* Test whether a device is a memory device */
  111. int
  112. gs_device_is_memory(const gx_device *dev)
  113. {    /* We can't just compare the procs, or even an individual proc, */
  114.     /* because we might be tracing.  Compare the device name, */
  115.     /* and hope for the best. */
  116.     const char *name = dev->dname;
  117.     int i;
  118.     for ( i = 0; i < 6; i++ )
  119.       if ( name[i] != "image("[i] ) return 0;
  120.     return 1;
  121. }
  122.  
  123. /* Ensure that the data bytes are in big-endian order. */
  124. /* This is no longer needed. */
  125. void
  126. gdev_mem_ensure_byte_order(gx_device_memory *dev)
  127. {
  128. }
  129.  
  130. /* Close a memory device, freeing the data area if appropriate. */
  131. int
  132. mem_close(gx_device *dev)
  133. {    if ( mdev->memory_procs != 0 )
  134.       (*mdev->memory_procs->free)((char *)mdev->base,
  135.         1, (uint)gdev_mem_bitmap_size(mdev), "mem_close");
  136.     return 0;
  137. }
  138.  
  139. /* Copy a scan line to a client. */
  140. #undef chunk
  141. #define chunk byte
  142. int
  143. mem_get_bits(gx_device *dev, int y, byte *str, byte **actual_data)
  144. {    byte *src;
  145.     if ( y < 0 || y >= dev->height )
  146.         return gs_error_rangecheck;
  147.     src = scan_line_base(mdev, y);
  148.     if ( actual_data == 0 )
  149.         memcpy(str, src, gx_device_raster(dev, 0));
  150.     else
  151.         *actual_data = src;
  152.     return 0;
  153. }
  154.  
  155. /* Return the xfont procedure vector. */
  156. gx_xfont_procs *
  157. mem_get_xfont_procs(gx_device *dev)
  158. {    gx_device *target = mdev->target;
  159.     return (target == 0 ? gx_default_get_xfont_procs(dev) :
  160.         (*target->procs->get_xfont_procs)(target));
  161. }
  162.  
  163. /* Return the xfont device. */
  164. gx_device *
  165. mem_get_xfont_device(gx_device *dev)
  166. {    gx_device *target = mdev->target;
  167.     return (target == 0 ? gx_default_get_xfont_device(dev) :
  168.         (*target->procs->get_xfont_device)(target));
  169. }
  170.  
  171. /* ------ Monochrome ------ */
  172.  
  173. /* Procedures */
  174. private dev_proc_copy_mono(mem_mono_copy_mono);
  175. private dev_proc_fill_rectangle(mem_mono_fill_rectangle);
  176.  
  177. /* The device descriptor. */
  178. private gx_device_procs mem_mono_procs =
  179.   mem_procs(gx_default_map_rgb_color, gx_default_map_color_rgb,
  180.     mem_mono_copy_mono, gx_default_copy_color, mem_mono_fill_rectangle);
  181.  
  182. /* The instance is public. */
  183. const gx_device_memory mem_mono_device =
  184.   mem_device("image(mono)", 1, mem_mono_procs);
  185.  
  186. /* Convert x coordinate to byte offset in scan line. */
  187. #define x_to_byte(x) ((x) >> 3)
  188.  
  189. /* Fill a rectangle with a color. */
  190. #undef chunk
  191. #define chunk mono_chunk
  192. private int
  193. mem_mono_fill_rectangle(gx_device *dev, int x, int y, int w, int h,
  194.   gx_color_index color)
  195. {    uint bit;
  196.     chunk right_mask;
  197.     byte fill;
  198.     declare_scan_ptr(dest);
  199.     fit_fill(dev, x, y, w, h);
  200.     setup_rect(dest);
  201. #define write_loop(stat)\
  202.  { int line_count = h;\
  203.    chunk *ptr = dest;\
  204.    do { stat; inc_chunk_ptr(ptr, draster); }\
  205.    while ( --line_count );\
  206.  }
  207. #define write_partial(msk)\
  208.    if ( fill ) write_loop(*ptr |= msk)\
  209.    else write_loop(*ptr &= ~msk)
  210.     switch ( color )
  211.        {
  212.     case 0: fill = mdev->invert; break;
  213.     case 1: fill = ~mdev->invert; break;
  214.     case gx_no_color_index: return 0;        /* transparent */
  215.     default: return -1;        /* invalid */
  216.        }
  217.     bit = x & chunk_align_bit_mask;
  218.     if ( bit + w <= chunk_bits )
  219.        {    /*
  220.          * Only one word. We have to split following statement
  221.          * because of a bug in the Xenix C compiler (it produces
  222.          * a signed rather than an unsigned shift if we don't
  223.          * split).
  224.          */
  225.         set_mono_thin_mask(right_mask, w, bit);
  226.        }
  227.     else
  228.        {    int byte_count;
  229.         if ( bit )
  230.            {    chunk mask;
  231.             set_mono_left_mask(mask, bit);
  232.             write_partial(mask);
  233.             dest++;
  234.             w += bit - chunk_bits;
  235.            }
  236.         set_mono_right_mask(right_mask, w & chunk_bit_mask);
  237.         if ( (byte_count = (w >> 3) & -chunk_bytes) != 0 )
  238.            {    write_loop(memset(ptr, fill, byte_count));
  239.             inc_chunk_ptr(dest, byte_count);
  240.            }
  241.        }
  242.     if ( right_mask )
  243.         write_partial(right_mask);
  244.     return 0;
  245. }
  246.  
  247. /* Copy a monochrome bitmap. */
  248.  
  249. /* Fetch a chunk from the source. */
  250. /* The source data are always stored big-endian. */
  251. /* Note that the macros always cast cptr, */
  252. /* so it doesn't matter what the type of cptr is. */
  253. /* cshift = chunk_bits - shift. */
  254. #undef chunk
  255. #if arch_is_big_endian
  256. #  define chunk uint
  257. #  define cfetch_right(cptr, shift, cshift)\
  258.     (cfetch_aligned(cptr) >> shift)
  259. #  define cfetch_left(cptr, shift, cshift)\
  260.     (cfetch_aligned(cptr) << shift)
  261. /* Fetch a chunk that straddles a chunk boundary. */
  262. #  define cfetch2(cptr, cskew, skew)\
  263.     (cfetch_left(cptr, cskew, skew) +\
  264.      cfetch_right((chunk *)(cptr) + 1, skew, cskew))
  265. #else                /* little-endian */
  266. #  define chunk ushort
  267. private const ushort right_masks2[9] = {
  268.     0xffff, 0x7f7f, 0x3f3f, 0x1f1f, 0x0f0f, 0x0707, 0x0303, 0x0101, 0x0000
  269. };
  270. private const ushort left_masks2[9] = {
  271.     0xffff, 0xfefe, 0xfcfc, 0xf8f8, 0xf0f0, 0xe0e0, 0xc0c0, 0x8080, 0x0000
  272. };
  273. #  define ccont(cptr, off) (((chunk *)(cptr))[off])
  274. #  define cfetch_right(cptr, shift, cshift)\
  275.     ((shift) < 8 ?\
  276.      ((ccont(cptr, 0) >> (shift)) & right_masks2[shift]) +\
  277.       (ccont(cptr, 0) << (cshift)) :\
  278.      ((chunk)*(byte *)(cptr) << (cshift)) & 0xff00)
  279. #  define cfetch_left(cptr, shift, cshift)\
  280.     ((shift) < 8 ?\
  281.      ((ccont(cptr, 0) << (shift)) & left_masks2[shift]) +\
  282.       (ccont(cptr, 0) >> (cshift)) :\
  283.      ((ccont(cptr, 0) & 0xff00) >> (cshift)) & 0xff)
  284. /* Fetch a chunk that straddles a chunk boundary. */
  285. /* We can avoid testing the shift amount twice */
  286. /* by expanding the cfetch_left/right macros in-line. */
  287. #  define cfetch2(cptr, cskew, skew)\
  288.     ((cskew) < 8 ?\
  289.      ((ccont(cptr, 0) << (cskew)) & left_masks2[cskew]) +\
  290.       (ccont(cptr, 0) >> (skew)) +\
  291.       (((chunk)(((byte *)(cptr))[2]) << (cskew)) & 0xff00) :\
  292.      (((ccont(cptr, 0) & 0xff00) >> (skew)) & 0xff) +\
  293.       ((ccont(cptr, 1) >> (skew)) & right_masks2[skew]) +\
  294.        (ccont(cptr, 1) << (cskew)))
  295. #endif
  296. /* Since source and destination are both always big-endian, */
  297. /* fetching an aligned chunk never requires byte swapping. */
  298. #  define cfetch_aligned(cptr)\
  299.     (*(chunk *)(cptr))
  300.  
  301. /* copy_function and copy_shift get added together for dispatch */
  302. typedef enum {
  303.     copy_or = 0, copy_store, copy_and, copy_funny
  304. } copy_function;
  305. /* copy_right/left is not an enum, because compilers complain about */
  306. /* an enumeration clash when these are added to a copy_function. */
  307. #define copy_right ((copy_function)0)
  308. #define copy_left ((copy_function)4)
  309. typedef struct {
  310.     short invert;
  311.     ushort op;            /* copy_function */
  312. } copy_mode;
  313. /* Map from <c0,c1,invert> to copy_mode. */
  314. #define cm(i,op) { i, (ushort)op }
  315. private copy_mode copy_modes[9*2] = {
  316.     cm(-1, copy_funny),        /* NN */
  317.     cm(-1, copy_and),        /* N0 */
  318.     cm(0, copy_or),            /* N1 */
  319.     cm(0, copy_and),        /* 0N */
  320.     cm(0, copy_funny),        /* 00 */
  321.     cm(0, copy_store),        /* 01 */
  322.     cm(-1, copy_or),        /* 1N */
  323.     cm(-1, copy_store),        /* 10 */
  324.     cm(0, copy_funny),        /* 11 */
  325.     cm(-1, copy_funny),        /* NNi */
  326.     cm(0, copy_or),            /* N1i */
  327.     cm(-1, copy_and),        /* N0i */
  328.     cm(-1, copy_or),        /* 1Ni */
  329.     cm(0, copy_funny),        /* 11i */
  330.     cm(-1, copy_store),        /* 10i */
  331.     cm(0, copy_and),        /* 0Ni */
  332.     cm(0, copy_store),        /* 01i */
  333.     cm(0, copy_funny)        /* 00i */
  334. };
  335. private int
  336. mem_mono_copy_mono(gx_device *dev,
  337.   const byte *base, int sourcex, int sraster, gx_bitmap_id id,
  338.   int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
  339. {    register const byte *bptr;        /* actually chunk * */
  340.     int dbit, wleft;
  341.     uint mask;
  342.     copy_mode mode;
  343. #define function (copy_function)(mode.op)
  344.     declare_scan_ptr_as(dbptr, byte *);
  345. #define optr ((chunk *)dbptr)
  346.     register int skew;
  347.     register uint invert;
  348.     fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
  349. #if gx_no_color_index_value != -1        /* hokey! */
  350.     if ( zero == gx_no_color_index ) zero = -1;
  351.     if ( one == gx_no_color_index ) one = -1;
  352. #endif
  353. #define izero (int)zero
  354. #define ione (int)one
  355.     mode =
  356.       copy_modes[(mdev->invert & 9) + izero + izero + izero + ione + 4];
  357. #undef izero
  358. #undef ione
  359.     invert = (uint)(int)mode.invert;    /* load register */
  360.     setup_rect_as(dbptr, byte *);
  361.     bptr = base + ((sourcex & ~chunk_align_bit_mask) >> 3);
  362.     dbit = x & chunk_align_bit_mask;
  363.     skew = dbit - (sourcex & chunk_align_bit_mask);
  364. /* Macros for writing partial chunks. */
  365. /* The destination pointer is always named optr, */
  366. /* and must be declared as chunk *. */
  367. /* cinvert may be temporarily redefined. */
  368. #define cinvert(bits) ((bits) ^ invert)
  369. #define write_or_masked(bits, mask, off)\
  370.   optr[off] |= (cinvert(bits) & mask)
  371. #define write_store_masked(bits, mask, off)\
  372.   optr[off] = ((optr[off] & ~mask) | (cinvert(bits) & mask))
  373. #define write_and_masked(bits, mask, off)\
  374.   optr[off] &= (cinvert(bits) | ~mask)
  375. /* Macros for writing full chunks. */
  376. #define write_or(bits)  *optr |= cinvert(bits)
  377. #define write_store(bits) *optr = cinvert(bits)
  378. #define write_and(bits) *optr &= cinvert(bits)
  379. /* Macro for incrementing to next chunk. */
  380. #define next_x_chunk\
  381.   bptr += chunk_bytes; dbptr += chunk_bytes
  382. /* Common macro for the end of each scan line. */
  383. #define end_y_loop(sdelta, ddelta)\
  384.   if ( --h == 0 ) break;\
  385.   bptr += sdelta; dbptr += ddelta
  386.     if ( (wleft = w + dbit - chunk_bits) <= 0 )
  387.        {    /* The entire operation fits in one (destination) chunk. */
  388.         set_mono_thin_mask(mask, w, dbit);
  389. #define write_single(wr_op, src)\
  390.   for ( ; ; )\
  391.    { wr_op(src, mask, 0);\
  392.      end_y_loop(sraster, draster);\
  393.    }
  394. #define write1_loop(src)\
  395.   switch ( function ) {\
  396.     case copy_or: write_single(write_or_masked, src); break;\
  397.     case copy_store: write_single(write_store_masked, src); break;\
  398.     case copy_and: write_single(write_and_masked, src); break;\
  399.     default: goto funny;\
  400.   }
  401.         if ( skew >= 0 )    /* single -> single, right/no shift */
  402.            {    int cskew = chunk_bits - skew;
  403.             write1_loop(cfetch_right(bptr, skew, cskew));
  404.            }
  405.         else if ( wleft <= skew )    /* single -> single, left shift */
  406.            {    int cskew = chunk_bits + skew;
  407.             skew = -skew;
  408.             write1_loop(cfetch_left(bptr, skew, cskew));
  409.            }
  410.         else            /* double -> single */
  411.            {    int cskew = -skew;
  412.             skew += chunk_bits;
  413.             write1_loop(cfetch2(bptr, cskew, skew));
  414.            }
  415. #undef write1_loop
  416. #undef write_single
  417.        }
  418.     else if ( wleft <= skew )
  419.        {    /* 1 source chunk -> 2 destination chunks. */
  420.         /* This is an important special case for */
  421.         /* both characters and halftone tiles. */
  422.         register uint bits;
  423.         uint rmask;
  424.         int cskew = chunk_bits - skew;
  425.         set_mono_left_mask(mask, dbit);
  426.         set_mono_right_mask(rmask, wleft);
  427. #undef cinvert
  428. #define cinvert(bits) (bits)        /* pre-inverted here */
  429. #if arch_is_big_endian            /* no byte swapping */
  430. #  define write_1to2(wr_op)\
  431.   for ( ; ; )\
  432.    { bits = cfetch_aligned(bptr) ^ invert;\
  433.      wr_op(bits >> skew, mask, 0);\
  434.      wr_op(bits << cskew, rmask, 1);\
  435.      end_y_loop(sraster, draster);\
  436.    }
  437. #else                    /* byte swapping */
  438. #  define write_1to2(wr_op)\
  439.   for ( ; ; )\
  440.    { wr_op(cfetch_right(bptr, skew, cskew) ^ invert, mask, 0);\
  441.      wr_op(cfetch_left(bptr, cskew, skew) ^ invert, rmask, 1);\
  442.      end_y_loop(sraster, draster);\
  443.    }
  444. #endif
  445.         switch ( function )
  446.            {
  447.         case copy_or: write_1to2(write_or_masked); break;
  448.         case copy_store: write_1to2(write_store_masked); break;
  449.         case copy_and: write_1to2(write_and_masked); break;
  450.         default: goto funny;
  451.            }
  452. #undef cinvert
  453. #define cinvert(bits) ((bits) ^ invert)
  454. #undef write_1to2
  455.        }
  456.     else
  457.        {    /* More than one source chunk and more than one */
  458.         /* destination chunk are involved. */
  459.         uint rmask;
  460.         int words = (wleft & ~chunk_bit_mask) >> 3;
  461.         uint sskip = sraster - words;
  462.         uint dskip = draster - words;
  463.         register uint bits;
  464.         set_mono_left_mask(mask, dbit);
  465.         set_mono_right_mask(rmask, wleft & chunk_bit_mask);
  466.         if ( skew == 0 )    /* optimize the aligned case */
  467.            {
  468. #define write_aligned(wr_op, wr_op_masked)\
  469.   for ( ; ; )\
  470.    { int count = wleft;\
  471.      /* Do first partial chunk. */\
  472.      wr_op_masked(cfetch_aligned(bptr), mask, 0);\
  473.      /* Do full chunks. */\
  474.      while ( (count -= chunk_bits) >= 0 )\
  475.       { next_x_chunk; wr_op(cfetch_aligned(bptr)); }\
  476.      /* Do last chunk */\
  477.      if ( count > -chunk_bits )\
  478.       { wr_op_masked(cfetch_aligned(bptr + chunk_bytes), rmask, 1); }\
  479.      end_y_loop(sskip, dskip);\
  480.    }
  481.             switch ( function )
  482.               {
  483.               case copy_or:
  484.                 write_aligned(write_or, write_or_masked);
  485.                 break;
  486.               case copy_store:
  487.                 write_aligned(write_store, write_store_masked);
  488.                 break;
  489.               case copy_and:
  490.                 write_aligned(write_and, write_and_masked);
  491.                 break;
  492.               default:
  493.                 goto funny;
  494.               }
  495. #undef write_aligned
  496.            }
  497.         else            /* not aligned */
  498.            {    int ccase =
  499.               (skew >= 0 ? copy_right :
  500.                ((bptr += chunk_bytes), copy_left))
  501.               + (int)function;
  502.             int cskew = -skew & chunk_bit_mask;
  503.             skew &= chunk_bit_mask;
  504.             for ( ; ; )
  505.                {    int count = wleft;
  506. #define prefetch_right\
  507.   bits = cfetch_right(bptr, skew, cskew)
  508. #define prefetch_left\
  509.   bits = cfetch2(bptr - chunk_bytes, cskew, skew)
  510. #define write_unaligned(wr_op, wr_op_masked)\
  511.   wr_op_masked(bits, mask, 0);\
  512.   /* Do full chunks. */\
  513.   while ( count >= chunk_bits )\
  514.     { bits = cfetch2(bptr, cskew, skew);\
  515.       next_x_chunk; wr_op(bits); count -= chunk_bits;\
  516.     }\
  517.   /* Do last chunk */\
  518.   if ( count > 0 )\
  519.     { bits = cfetch_left(bptr, cskew, skew);\
  520.       if ( count > skew ) bits += cfetch_right(bptr + chunk_bytes, skew, cskew);\
  521.       wr_op_masked(bits, rmask, 1);\
  522.     }
  523.                 switch ( ccase )
  524.                   {
  525.                   case copy_or + copy_left:
  526.                     prefetch_left; goto uor;
  527.                   case copy_or + copy_right:
  528.                     prefetch_right;
  529. uor:                    write_unaligned(write_or, write_or_masked);
  530.                     break;
  531.                   case copy_store + copy_left:
  532.                     prefetch_left; goto ustore;
  533.                   case copy_store + copy_right:
  534.                     prefetch_right;
  535. ustore:                    write_unaligned(write_store, write_store_masked);
  536.                     break;
  537.                   case copy_and + copy_left:
  538.                     prefetch_left; goto uand;
  539.                   case copy_and + copy_right:
  540.                     prefetch_right;
  541. uand:                    write_unaligned(write_and, write_and_masked);
  542.                     break;
  543.                   default:
  544.                     goto funny;
  545.                   }
  546.                 end_y_loop(sskip, dskip);
  547. #undef write_unaligned
  548. #undef prefetch_left
  549. #undef prefetch_right
  550.                }
  551.            }
  552.        }
  553. #undef end_y_loop
  554. #undef next_x_chunk
  555.     return 0;
  556.     /* Handle the funny cases that aren't supposed to happen. */
  557. funny:    return (invert ? -1 : mem_mono_fill_rectangle(dev, x, y, w, h, zero));
  558. #undef optr
  559. }
  560.